﻿var timeOut;
var box = $('#report-box');
$(function () {
    Scroll();
    Resize();
    box.click(Out);
    box.mouseenter(function () { clearTimeout(timeOut) });
    box.mouseleave(function () { timeOut = setTimeout("Out()", 3000) });
    $(window).scroll(Scroll).resize(Resize);
})

function Out() {
    slideAtEnd();
    setTimeout("box.parent().remove()", 500);
    $(window).unbind("scroll resize");
}

function Resize() {
    var windowEle = $(window);
    if (windowEle.width() <= 300) {
        box.width(windowEle.width() * 0.7);
    }
    else {
        box.width('auto');
    }
    box.css('left', ($(window).width() / 2) - (box.outerWidth() / 2) + 'px')
}

var fixed;
function Scroll() {
    //fixed
    if ($('body').scrollTop() >= $('header').height()) {
        box.css({
            position: 'fixed',
            top: '0px',
        })
    }
    else {
        box.css({
            position: 'absolute',
            top: $('header').height(),
        })
    }
}

function slideAtStart() {
    box.removeAttr("hidden");
    var maxHeight = box.find('span').height();
    box.css({
        height: maxHeight + 'px',
        padding: '20px',
        opacity: '1'
    })
}

function slideAtEnd() {
    box.css({
        height: '0px',
        padding: '0 20px',
        opacity: '0'
    })
}